package j12;

import cn.hutool.core.thread.ThreadUtil;

/**
 * @author chengshuai
 * @date 2021/5/5 19:46
 */
public class WaitNotifyDemo {

    static Object object = new Object();
    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (object) {
                System.out.println(Thread.currentThread().getName() + "\t" + "-------come in");
                try {
                    object.wait();
                } catch (InterruptedException e) {
                   e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "\t" + "-------执行结束");
            }
        }, "A").start();


        new Thread(() -> {
            synchronized (object) {
                System.out.println("等待3秒");
                ThreadUtil.sleep(3000);
                System.out.println("唤醒线程A");
                object.notify();
                System.out.println(Thread.currentThread().getName() + "\t" + "-------执行结束");
            }
        }, "B").start();
    }
}
